<?php


namespace app\app\controller\user;


use app\model\LinkmanModel;
use support\Request;

class Linkman
{
    protected $user_id = 0;

    public function beforeAction(Request $request){
        $this->user_id = $request->user_id;
    }
    public function lst(){
        $linkmanModel = new LinkmanModel();
        $linkmanList = $linkmanModel->where(['user_id' => $this->user_id])->select();
        return success($linkmanList);
    }
    public function add(){
        $linkmanModel = new LinkmanModel();
        $_linkman = json_decode($_POST['linkman'], true);
        $_linkman['user_id']=$this->user_id;
        $res = $linkmanModel->insert($_linkman);
        return $res ? success(null,0,"添加成功") : error(1,"添加失败");
    }
    public function edt(){
        $linkmanModel = new LinkmanModel();
        $_linkman = json_decode($_POST['linkman'], true);
        $res = $linkmanModel->update($_linkman);
        return $res ? success(null,0,"修改成功") : error(1,"修改失败");

    }
    public function del(){
        if(input('id',0)<1){
            return error(1,'id is null');
        }
        $linkmanModel = new LinkmanModel();
        $res = $linkmanModel->where(['id' => input('id')])->delete();
        return $res ? success(null,0,"删除成功") : error(1,"删除失败");
    }
}